package userServlet;

import userServlet.bean.User;
import userServlet.dao.ServletDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class UserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletDaoImpl dao = new ServletDaoImpl();
        req.setCharacterEncoding("utf-8");
        String userName = req.getParameter("userName");
        String password = req.getParameter("password");
        List<User> userInfo = dao.getUserInfo();
        for (User user : userInfo) {
            System.out.println("用户："+user.getUserName()+"，密码："+user.getPassword());
            if (userName.equals(user.getUserName()) && password.equals(user.getPassword())){
                req.getRequestDispatcher("/success.html").forward(req,resp);
            } else {
                req.getRequestDispatcher("/false.html").forward(req,resp);
            }
        }
    }
}
